﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Data;

namespace PracticeProject
{
    public partial class SelectParen : Form
    {
        List<Goal> Goals;
        public int ParentGoalId;
        public SelectParen(int old_id)
        {
            InitializeComponent();
            SetView();
            ParentGoalId = old_id;
        }

        void SetView()
        {
            ElementCollection data = ElementCollection.OpenCollectionFromXml();
            Goals = data.GetGoals(DTSelectDate.Value);
            
            pnlGoals.Controls.Clear();
            for (int i = 0; i < Goals.Count; i++)
            {
                LinkLabel l = new LinkLabel();
                l.Text = Goals[i].Description;

                l.Location = new Point(10, 17 * i);

                l.Click += new EventHandler(l_Click);

                switch (Goals[i].Priority)
                {
                    case 0:
                        l.ForeColor = Color.Chocolate;

                        break;
                    case 1:
                        l.ForeColor = Color.Black;
                        break;
                    case 2:
                        l.ForeColor = Color.Green;
                        break;
                }



                pnlGoals.Controls.Add(l);

            }
        }

        void l_Click(object sender, EventArgs e)
        {
            int i = pnlGoals.Controls.IndexOf((Control)sender);
            ParentGoalId = Goals[i].ID;
            
            Close();
        }

        private void dateTimePicker1_ValueChanged(object sender, EventArgs e)
        {
            SetView();
        }
    }
}